import { prisma } from "@/lib/db";
import { handlerApi } from "@/lib/handlerApi";
import dayjs from "dayjs";
import fs from "fs";
import fsExtra from "fs-extra";
import childProcess from "child_process";
import { NextRequest } from "next/server";
const { execSync } = childProcess;
import path from "path";
import { UploadFormProp, uploadZip } from "@/app/actions/line_log";

const uploadImg = handlerApi(async (req: NextRequest) => {
  const formData = await req.formData();
  const file: File = formData.get("file") as File;
  let formBody: UploadFormProp = JSON.parse(formData.get("formData") as string);
  //   // console.log(file);
  if (!file) {
    throw Error("No files received.");
  }
  if (!(formBody.showLog === false)) {
    const result = await prisma.user.findUnique({
      where: {
        name: formBody.username,
        password: formBody.password,
      },
    });
    if (!result) {
      throw Error("用户名或密码错误");
    }
  }
  await uploadZip(file, formBody);
  // const res = await sharp().com.toFile('./ceshi.png');
  // return process.env.FILE_STORE;
  return "发布成功";
});
export const POST = uploadImg;



